#include <stdio.h>
#define MAXNUM 1000

int countword(char[]); /*function prorotype*/

int main()
{
    char message[MAXNUM];
    int numchar;

    printf("\nType in any number of words: ");
    gets(message);
    numchar = countword(message);
    printf("The number of words just entered is %d\n", numchar);

    return 0;
}

int countword(char list[])
#define YES 1
#define NO 0
{
    int i, inaword, count = 0;

    inaword = NO;
    for (i = 0; list[i] != '\0'; i++)
    {
        if (list[i] == ' ')
            inaword = NO;
        else if (inaword == NO)
        {
            inaword = YES;
            count++;
        }
    }

    return (count);
}